package cn.wolfcode.shop.seckillserver.mapper;

import cn.wolfcode.shop.seckillapi.domain.SeckillGood;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SeckillMapper {

    @Select("select * from t_seckill_goods")
    List<SeckillGood> list();

    @Select("select * from t_seckill_goods where good_id = #{goodId}")
    SeckillGood findByGoodId(@Param("goodId") Long goodId);

    @Update("update t_seckill_goods set stock_count = (stock_count - 1) where good_id = #{goodId} and stock_count >0")
    int reduce(@Param("goodId")Long goodId);

    @Update("update t_order_info set status = 3 where order_no = #{orderNo} and status = 0")
    int timeOutCancelOrder(@Param("orderNo")String orderNo);

    @Update("update t_seckill_goods set stock_count = (stock_count + 1) where good_id = #{goodId}")
    void updateByGoodId(@Param("goodId")Long goodId);
}
